import random
import numpy as np
import matplotlib.pyplot as plt
import json
from aStar import aStar
from render import render
from utils import homePos
class RandomMap:
  def __init__(self):
    # with open("map.txt", "r") as file:
    #   self.map = file.readlines()
    #   self.map = [list(map(str, line.strip().split())) for line in self.map]
    #   self.map=np.array(self.map)
    
    with open("data.json", "r",encoding='utf-8') as file:
      jsonData = json.load(file)
      self.map=np.array(jsonData['map'])
      for item in jsonData['propVos']:
        y=item['x']//50
        x=item['y']//50
        self.map[x,y]='B'
      
      for play in jsonData['playerStateVos']:
        y=play['x']
        x=play['y']
        self.map[x//50,y//50]='P'
      
      for a in jsonData['animalStateVos']:
        x,y=a['y'],a['x']
        self.map[x//50,y//50]='A'
        
      
      
    start=(11,2)
    end=(3,26)
   
    route = aStar(self.map, start, end)
    copy=self.map.copy()
    for x,y in route:
      if copy[x][y]!='s' and copy[x][y]!='t':
        # copy[x][y]='o'
        pass
    render(copy)
RandomMap()

